home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / nodefnd / gridbrow.bas < prev    next >
BASIC Source File  |  1995-10-23  |  8KB  |  267 lines

  1. 'Programer  : Antonio Macedo
  2. 'Compuserve : 75210.3332
  3. 'Date       : 10/06/93
  4. 'Version    : 1.0
  5. 'Total Hours: 7
  6.  
  7. 'The folowing code is designed to be as generic as possible,
  8. 'so you can easyly implement it on your aplication.
  9. 'Feel free to use and distribute this code.
  10. 'Just do me three favors :
  11. '- Send me an message telling what you think about this routines.
  12. '- Send me an message telling the modifications that you have made on the routines.
  13. '- DO NOT DELETE MY COMMENTS, ESPECIALY CREDITS AND THESE THREE FAVORS.
  14.  
  15.  
  16.  
  17. 'This is the array used to hold bookmarks for the grid operations
  18. 'adjust the first dimension maching the number of grids you use
  19. 'adjust the second dimension maching the maximum # of rows on the grids
  20.  
  21. Global Mark(1 To 1, 0 To 15) As String
  22.  
  23. '<<< I M P O R T A N T >>>
  24. '- Do not forget to open the files and fill the grid
  25. '  and the bookmark array with data.
  26.  
  27. Sub Grd_Copy (Grd As Grid, ByVal r, ByVal c, ByVal r2, ByVal c2 As Integer)
  28. 'Copy text from
  29. ' r , c
  30. 'To
  31. ' r2, c2
  32. 'In grid Grd
  33.  
  34. Static s As String
  35.     Grd.Row = r
  36.     Grd.Col = c
  37.     s = Grd.Text
  38.     Grd.Row = r2
  39.     Grd.Col = c2
  40.     Grd.Text = s
  41.  
  42. End Sub
  43.  
  44. Sub Grd_Write (Grd As Grid, ByVal r As Integer, ByVal c As Integer, ByVal s As String)
  45. 'Write string
  46. ' s
  47. 'To
  48. ' r , c
  49. 'In grid Grd
  50.  
  51.     Grd.Row = r
  52.     Grd.Col = c
  53.     Grd.Text = s
  54. End Sub
  55.  
  56. Sub Grid_Browse (KeyCode As Integer, Shift As Integer, Grd As Grid, Tbl As Table, bk As Integer)
  57.  
  58. 'Parameters definition
  59.  
  60. 'KeyCode - Comes directly from KeyDown event
  61. 'Shift   - Comes directly from KeyDown event
  62. 'Grd     - Grid control where the cursor is located
  63. 'Tbl     - Table object that is the data source
  64. 'bk      - Bookmark array index corresponding to the current Grid
  65. '                         -----
  66.  
  67.  
  68. Static CurRow, Range As Integer
  69.  
  70. 'Check for UnderFlow
  71. 'If the table does not fill entirely the grid then exit
  72. If Mark(bk, Grd.Rows - 1) = "" Then Exit Sub
  73.  
  74.  
  75.  
  76. '{PgDn} or {Ctrl}+{PgDn} or {Ctrl}+{Down}
  77.  
  78. If ((KeyCode = 34) Or (KeyCode = 40 And Shift = 2)) And Not Tbl.EOF Then
  79.     'Go to the bookmark corresponding to the last grid line
  80.     Tbl.Bookmark = Mark(bk, Grd.Rows - Grd.FixedRows)
  81.     'Store the cursor position
  82.     CurRow = Grd.Row
  83.     'If {PgDn} or {Ctrl}+{Down} then range = grid number of lines
  84.     'If {Ctrl}+{PgDn} then range = 3 times grid number of lines
  85.     If KeyCode = 34 And Shift = 2 Then
  86.         Range = (Grd.Rows - Grd.FixedRows) * 3
  87.     Else
  88.         Range = Grd.Rows - Grd.FixedRows
  89.     End If
  90.     'MoveNext until range or EOF
  91.     For r = Grd.FixedRows To Range
  92.         Tbl.MoveNext
  93.         If Tbl.EOF Then
  94.             Tbl.MovePrevious
  95.             Exit For
  96.         End If
  97.     Next
  98.     'Refresh grid and bookmark array data backwards
  99.     For r = Grd.Rows - 1 To Grd.FixedRows Step -1
  100.         For c = Grd.FixedCols To Grd.Cols - 1
  101.             Grd_Write Grd, r, c, Tbl(c - Grd.FixedCols)
  102.         Next
  103.         Mark(bk, r) = Tbl.Bookmark
  104.         Tbl.MovePrevious
  105.     Next
  106.     'Restore cursor position
  107.     Grd.Row = CurRow
  108.     'Change KeyCode value to trig the SelChange event
  109.     KeyCode = 37
  110. End If
  111.  
  112.  
  113. '{PgUp} or {Ctrl}+{PgUp} or {Ctrl}+{Up}
  114.  
  115. If ((KeyCode = 33) Or (KeyCode = 38 And Shift = 2)) And Not Tbl.BOF Then
  116.     'Go to the bookmark corresponding to the first grid line
  117.     Tbl.Bookmark = Mark(bk, Grd.FixedRows)
  118.     'Store the cursor position
  119.     CurRow = Grd.Row
  120.     'If {PgUp} or {Ctrl}+{Up} then range = grid number of lines
  121.     'If {Ctrl}+{PgUp} then range = 3 times grid number of lines
  122.     If KeyCode = 33 And Shift = 2 Then
  123.         Range = (Grd.Rows - Grd.FixedRows) * 3
  124.     Else
  125.         Range = Grd.Rows - Grd.FixedRows
  126.     End If
  127.     'MovePrevious until range or BOF
  128.     For r = Grd.FixedRows To Range
  129.         Tbl.MovePrevious
  130.         If Tbl.BOF Then
  131.             Tbl.MoveNext
  132.             Exit For
  133.         End If
  134.     Next
  135.     'Refresh grid and bookmark array data
  136.     For r = Grd.FixedRows To Grd.Rows - 1
  137.         For c = Grd.FixedCols To Grd.Cols - 1
  138.             Grd_Write Grd, r, c, Tbl(c - Grd.FixedCols)
  139.         Next
  140.         Mark(bk, r) = Tbl.Bookmark
  141.         Tbl.MoveNext
  142.     Next
  143.     'Restore cursor position
  144.     Grd.Row = CurRow
  145.     'Change KeyCode value to trig the SelChange event
  146.     KeyCode = 37
  147. End If
  148.  
  149.  
  150. '{Down} on the last grid line - Scroll Down
  151.  
  152. If Grd.Row = Grd.Rows - Grd.FixedRows And KeyCode = 40 And Not Tbl.EOF Then
  153.     'Go to the bookmark corresponding to the last grid line
  154.     Tbl.Bookmark = Mark(bk, Grd.Rows - Grd.FixedRows)
  155.     'Read the next record
  156.     Tbl.MoveNext
  157.     If Not Tbl.EOF Then
  158.         'Scroll grid and bookmark array data one row up
  159.         For r = Grd.FixedRows To (Grd.Rows - Grd.FixedRows) - 1
  160.             For c = Grd.FixedCols To Grd.Cols - 1
  161.                 Grd_Copy Grd, r + 1, c, r, c
  162.             Next
  163.             Mark(bk, r) = Mark(bk, r + 1)
  164.         Next
  165.         'Write the current record on the last grid line
  166.         For c = Grd.FixedCols To Grd.Cols - 1
  167.             Grd_Write Grd, r, c, Tbl(c - Grd.FixedCols)
  168.         Next
  169.         'Update bookmark array
  170.         Mark(bk, Grd.Rows - Grd.FixedRows) = Tbl.Bookmark
  171.     End If
  172. End If
  173.  
  174.  
  175. '{Up} on the first grid line - Scroll Up
  176.  
  177. If Grd.Row = Grd.FixedRows And KeyCode = 38 And Not Tbl.BOF Then
  178.     'Go to the bookmark corresponding to the first grid line
  179.     Tbl.Bookmark = Mark(bk, Grd.FixedRows)
  180.     'Read the previous record
  181.     Tbl.MovePrevious
  182.     If Not Tbl.BOF Then
  183.         'Scroll grid and bookmark array data one row down
  184.         For r = Grd.Rows - 1 To Grd.FixedRows + 1 Step -1
  185.             For c = Grd.FixedCols To Grd.Cols - 1
  186.                 Grd_Copy Grd, r - 1, c, r, c
  187.             Next
  188.             Mark(bk, r) = Mark(bk, r - 1)
  189.         Next
  190.         'Write the current record on the first grid line
  191.         For c = Grd.FixedCols To Grd.Cols - 1
  192.             Grd_Write Grd, r, c, Tbl(c - Grd.FixedCols)
  193.         Next
  194.         'Update bookmark array
  195.         Mark(bk, Grd.FixedRows) = Tbl.Bookmark
  196.     End If
  197. End If
  198.  
  199.  
  200. '{A} to {Z} - Seek first record begining with the pressed letter using the current index
  201.  
  202. If KeyCode >= 65 And KeyCode <= 90 Then
  203.     Tbl.Seek ">=", Chr$(KeyCode)
  204.     If Not Tbl.NoMatch Then
  205.         'Refresh grid and bookmark array data
  206.         For r = Grd.FixedRows To Grd.Rows - 1
  207.             For c = Grd.FixedCols To Grd.Cols - 1
  208.                 Grd_Write Grd, r, c, Tbl(c - Grd.FixedCols)
  209.             Next
  210.             Mark(bk, r) = Tbl.Bookmark
  211.             Tbl.MoveNext
  212.         Next
  213.         'Put the cursor on the first grid line
  214.         Grd.Row = Grd.FixedRows
  215.        'Change KeyCode value to trig the SelChange event
  216.         KeyCode = 37
  217.     End If
  218. End If
  219.  
  220.  
  221. '{Home} - Put the cursor on the first grid row
  222.  
  223. If KeyCode = 36 Then
  224.     Grd.Row = Grd.FixedRows
  225. End If
  226.  
  227.  
  228. '{End} - Put the cursor on the last grid row
  229.  
  230. If KeyCode = 35 Then
  231.     Grd.Row = Grd.Rows - Grd.FixedRows
  232. End If
  233.  
  234.  
  235. '{Ctrl}+{Home} - Go to the first record
  236.  
  237. If KeyCode = 36 And Shift = 2 Then
  238.     Tbl.MoveFirst
  239.     'Refresh grid and bookmark array data
  240.     For r = Grd.FixedRows To Grd.Rows - 1
  241.         For c = Grd.FixedCols To Grd.Cols - 1
  242.             Grd_Write Grd, r, c, Tbl(c - Grd.FixedCols)
  243.         Next
  244.         Mark(bk, r) = Tbl.Bookmark
  245.         Tbl.MoveNext
  246.     Next
  247. End If
  248.  
  249.  
  250. '{Ctrl}+{End} - Go to the last record
  251.  
  252. If KeyCode = 35 And Shift = 2 Then
  253.     Tbl.MoveLast
  254.     'Refresh grid and bookmark array data backwards
  255.     For r = Grd.Rows - 1 To Grd.FixedRows Step -1
  256.         For c = Grd.FixedCols To Grd.Cols - 1
  257.             Grd_Write Grd, r, c, Tbl(c - Grd.FixedCols)
  258.         Next
  259.         Mark(bk, r) = Tbl.Bookmark
  260.         Tbl.MovePrevious
  261.     Next
  262. End If
  263.  
  264.  
  265. End Sub
  266.  
  267.